/**
 * @Project TMHSCFX
 * @Author Tran Manh Hung
 * @Email: hungtmit@gmail.com | tmh@xwebgate.com
 * @Copyright © 2011 TMH. All rights reserved
 * @Createdate Apr 13, 2011
 * @Createtime 2:44:34 PM
 */

package com.tmh.study.fAS3AMTM.chap4
{
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.geom.Point;

	public class MultiCurves1 extends Sprite
	{
		private var numPoints:uint = 99;

		public function MultiCurves1()
		{
			super();
			addEventListener(Event.ADDED_TO_STAGE, addedToStageHandler);
		}

		private function addedToStageHandler(event:Event):void
		{
			initData();
		}

		private function initData():void
		{
			// first set up an array of random points
			var points:Vector.<Point> = new Vector.<Point>();

			for (var i:int = 0; i < numPoints; i++)
			{
				points[i] = new Point();
				points[i].x = Math.random() * stage.stageWidth;
				points[i].y = Math.random() * stage.stageHeight;
			}

			graphics.lineStyle(1);
			// now move to the first point
			graphics.moveTo(points[0].x, points[0].y);

			// and loop through each next successive pair
			for (i = 1; i < numPoints; i += 2)
			{
				graphics.curveTo(points[i].x, points[i].y, points[i + 1].x, points[i + 1].y);
			}
		}
	}
}